<!DOCTYPE html>
<html>
<head>
  <title>IGraphRequester.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/client/core/IGraphRequester.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.client.core;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import com.google.protobuf.InvalidProtocolBufferException;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.Response;
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
import com.taobao.igraph.client.common.*;
import com.taobao.igraph.client.config.HttpConnectionConfig;
import com.taobao.igraph.client.config.IGraphRequesterConfig;
import com.taobao.igraph.client.proto.PGQueryResultProtocol.MatchRecords;
import com.taobao.igraph.client.proto.PGQueryResultProtocol.PGResult;
import com.taobao.igraph.client.proto.PGQueryResultProtocol.PGResult.Status;
import com.taobao.igraph.client.proto.PGQueryResultProtocol.Result;
import com.taobao.igraph.client.proto.PGQueryResultProtocol.Result.ErrorResult;
import com.taobao.igraph.client.core.model.QueryResult;
import com.taobao.igraph.client.core.model.SingleQueryResult;

import lombok.NonNull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>30</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>public class IGraphRequester {</pre></td>
    </tr>
    <tr>
      <td class='line'>31</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l31s0'>    private static final Logger log = LoggerFactory.getLogger(IGraphRequester.class);</pre></td>
    </tr>
    <tr>
      <td class='line'>32</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private AsyncHttpClient httpClient;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>34</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l34s0'>    public IGraphRequester() {</pre></td>
    </tr>
    <tr>
      <td class='line'>35</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l35s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>37</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void init(IGraphRequesterConfig iGraphRequesterConfig) {</pre></td>
    </tr>
    <tr>
      <td class='line'>38</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l38s0'>        HttpConnectionConfig httpConnectionConfig = iGraphRequesterConfig.getHttpConnectionConfig();</pre></td>
    </tr>
    <tr>
      <td class='line'>39</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l39s0'>        AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();</pre></td>
    </tr>
    <tr>
      <td class='line'>40</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l40s0'>        AsyncHttpClientConfig asyncHttpClientConfig = builder</pre></td>
    </tr>
    <tr>
      <td class='line'>41</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                .setMaximumConnectionsTotal(iGraphRequesterConfig.getMaxConnTotal())</pre></td>
    </tr>
    <tr>
      <td class='line'>42</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                .setMaximumConnectionsPerHost(iGraphRequesterConfig.getMaxConnPerRoute())</pre></td>
    </tr>
    <tr>
      <td class='line'>43</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                .setAllowPoolingConnection(true).setWebSocketIdleTimeoutInMs(httpConnectionConfig.getSocketTimeout())</pre></td>
    </tr>
    <tr>
      <td class='line'>44</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                .setRequestTimeoutInMs(httpConnectionConfig.getConnectionRequestTimeout())</pre></td>
    </tr>
    <tr>
      <td class='line'>45</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                .setConnectionTimeoutInMs(httpConnectionConfig.getConnectTimeout()).build();</pre></td>
    </tr>
    <tr>
      <td class='line'>46</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l46s0'>        httpClient = new AsyncHttpClient(new NettyAsyncHttpProvider(asyncHttpClientConfig));</pre></td>
    </tr>
    <tr>
      <td class='line'>47</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l47s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>49</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>    <span id='l49s0' title='Executions: 1' class='covered'>public QueryResult sendSearchRequest(@NonNull RequestContext requestContext) throws IGraphServerException {</span></pre></td>
    </tr>
    <tr>
      <td class='line'>50</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l50s0'>        byte[] bytes = sendRequest(requestContext, RequestType.POST);</pre></td>
    </tr>
    <tr>
      <td class='line'>51</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l51s0'>        QueryResult queryResult = new QueryResult();</pre></td>
    </tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        PGResult pgResult;</pre></td>
    </tr>
    <tr>
      <td class='line'>53</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        try {</pre></td>
    </tr>
    <tr>
      <td class='line'>54</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l54s0'>            requestContext.beginResponseDecode();</pre></td>
    </tr>
    <tr>
      <td class='line'>55</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l55s0'>            pgResult = PGResult.parseFrom(bytes);</pre></td>
    </tr>
    <tr>
      <td class='line'>56</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l56s0'>            requestContext.endResponseDecode();</pre></td>
    </tr>
    <tr>
      <td class='line'>57</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l57s0'>        } catch (InvalidProtocolBufferException e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>58</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l58s0'>            requestContext.endResponseDecode();</pre></td>
    </tr>
    <tr>
      <td class='line'>59</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l59s0'>            throw new IGraphServerException("result format is wrong, with InvalidProtocolBufferException:["</pre></td>
    </tr>
    <tr>
      <td class='line'>60</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + e.getMessage() + "] and requestContext:[" + requestContext + "]", e);</pre></td>
    </tr>
    <tr>
      <td class='line'>61</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l61s0'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>62</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l62s0'>        checkStatus(pgResult.getStatus(), requestContext); // 检查返回状态，状态不正确直接抛出异常；</pre></td>
    </tr>
    <tr>
      <td class='line'>63</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l63s0'>        requestContext.beginResponseDecode();</pre></td>
    </tr>
    <tr>
      <td class='line'>64</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l64s0'>        List&lt;SingleQueryResult> results = parseResult(pgResult, requestContext);</pre></td>
    </tr>
    <tr>
      <td class='line'>65</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l65s0'>        requestContext.endResponseDecode();</pre></td>
    </tr>
    <tr>
      <td class='line'>66</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l66s0'>        queryResult.setResults(results);</pre></td>
    </tr>
    <tr>
      <td class='line'>67</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l67s0'>        return queryResult;</pre></td>
    </tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>70</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>    <span id='l70s0' title='Executions: 0' class='uncovered'>public void sendUpdateRequest(@NonNull RequestContext requestContext) throws IGraphUpdateException {</span></pre></td>
    </tr>
    <tr>
      <td class='line'>71</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l71s0'>        byte[] bytes = sendRequest(requestContext, RequestType.GET);</pre></td>
    </tr>
    <tr>
      <td class='line'>72</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l72s0'>        String response = new String(bytes);</pre></td>
    </tr>
    <tr>
      <td class='line'>73</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l73s0' title='Executions: 0' class='uncovered'>if (!response.contains("&lt;errno>0&lt;/errno>"))</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>74</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l74s0'>            throw new IGraphUpdateException("update failed, with response:[" + response + "]");</pre></td>
    </tr>
    <tr>
      <td class='line'>75</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>76</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l76s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>78</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void close() {</pre></td>
    </tr>
    <tr>
      <td class='line'>79</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l79s0' title='Executions: 0' class='uncovered'>if (httpClient != null)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>80</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            try {</pre></td>
    </tr>
    <tr>
      <td class='line'>81</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l81s0'>                httpClient.close();</pre></td>
    </tr>
    <tr>
      <td class='line'>82</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l82s0'>            } catch (Exception e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>83</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l83s0'>                log.error("close httpclient failed with Exception", e);</pre></td>
    </tr>
    <tr>
      <td class='line'>84</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l84s0'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>85</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>86</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l86s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>88</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    protected byte[] sendRequest(RequestContext requestContext, RequestType requestType) throws IGraphServerException {</pre></td>
    </tr>
    <tr>
      <td class='line'>89</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l89s0' title='Executions: 1' class='covered'>if (log.isDebugEnabled())</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>90</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l90s0'>            log.debug("sendRequest with requestContext:[{}]", requestContext);</pre></td>
    </tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>93</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        AsyncHttpClient.BoundRequestBuilder requestBuilder;</pre></td>
    </tr>
    <tr>
      <td class='line'>94</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l94s0' title='Executions: 1' class='covered'>if (requestType == RequestType.POST)</span> { // POST for search request</pre></td>
    </tr>
    <tr>
      <td class='line'>95</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l95s0'>            requestBuilder = httpClient.preparePost(requestContext.getServerAddress()).setBody(</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    requestContext.getRequestContent());</pre></td>
    </tr>
    <tr>
      <td class='line'>97</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>        <span id='l97s0' title='Executions: 0' class='uncovered'>}</span> else if (requestType == RequestType.GET) { // GET for update request</pre></td>
    </tr>
    <tr>
      <td class='line'>98</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l98s0'>            requestBuilder = httpClient.prepareGet(requestContext.getServerAddress()</pre></td>
    </tr>
    <tr>
      <td class='line'>99</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + requestContext.getRequestContent());</pre></td>
    </tr>
    <tr>
      <td class='line'>100</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>101</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l101s0'>            throw new IGraphClientException("Invalid requestType:[" + requestType + "]");</pre></td>
    </tr>
    <tr>
      <td class='line'>102</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>103</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        byte[] byteArray;</pre></td>
    </tr>
    <tr>
      <td class='line'>104</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        int statusCode;</pre></td>
    </tr>
    <tr>
      <td class='line'>105</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        try {</pre></td>
    </tr>
    <tr>
      <td class='line'>106</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l106s0'>            requestContext.beginServerRequest();</pre></td>
    </tr>
    <tr>
      <td class='line'>107</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l107s0'>            appendHeaders(requestContext, requestBuilder);</pre></td>
    </tr>
    <tr>
      <td class='line'>108</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l108s0'>            Response response = requestBuilder.execute().get();</pre></td>
    </tr>
    <tr>
      <td class='line'>109</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l109s0'>            statusCode = response.getStatusCode();</pre></td>
    </tr>
    <tr>
      <td class='line'>110</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>            <span id='l110s0' title='Executions: 1' class='covered'>if (statusCode &lt; 200</span> || <span id='l110s1' title='Executions: 1' class='covered'>statusCode >= 300)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>111</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l111s0'>                throw new IGraphServerException("Failed to sendRequest with statusCode:[" + statusCode</pre></td>
    </tr>
    <tr>
      <td class='line'>112</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        + "] and requestContext:[" + requestContext + "]");</pre></td>
    </tr>
    <tr>
      <td class='line'>113</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>114</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l114s0'>            byteArray = response.getResponseBodyAsBytes();</pre></td>
    </tr>
    <tr>
      <td class='line'>115</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l115s0'>            requestContext.endServerRequest();</pre></td>
    </tr>
    <tr>
      <td class='line'>116</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l116s0'>        } catch (IOException e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>117</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l117s0'>            requestContext.endServerRequest();</pre></td>
    </tr>
    <tr>
      <td class='line'>118</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l118s0'>            throw new IGraphServerException("Failed to sendRequest with IOException:[" + e.getMessage()</pre></td>
    </tr>
    <tr>
      <td class='line'>119</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + "] and requestContext:[" + requestContext + "]", e);</pre></td>
    </tr>
    <tr>
      <td class='line'>120</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l120s0'>        } catch (InterruptedException e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>121</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l121s0'>            requestContext.endServerRequest();</pre></td>
    </tr>
    <tr>
      <td class='line'>122</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l122s0'>            throw new IGraphServerException("Failed to sendRequest with InterruptedException:[" + e.getMessage()</pre></td>
    </tr>
    <tr>
      <td class='line'>123</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + "] and requestContext:[" + requestContext + "]", e);</pre></td>
    </tr>
    <tr>
      <td class='line'>124</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l124s0'>        } catch (ExecutionException e) {</pre></td>
    </tr>
    <tr>
      <td class='line'>125</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l125s0'>            requestContext.endServerRequest();</pre></td>
    </tr>
    <tr>
      <td class='line'>126</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l126s0'>            Throwable cause = e.getCause();</pre></td>
    </tr>
    <tr>
      <td class='line'>127</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>            <span id='l127s0' title='Executions: 0' class='uncovered'>if (cause != null</span> && <span id='l127s1' title='Executions: 0' class='uncovered'>cause instanceof TimeoutException)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>128</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l128s0'>                throw new IGraphTimeoutException("timeout to sendRequest, with TimeoutException:[" + cause.getMessage()</pre></td>
    </tr>
    <tr>
      <td class='line'>129</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        + "] and requestContext:[" + requestContext + "]", e);</pre></td>
    </tr>
    <tr>
      <td class='line'>130</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            } else {</pre></td>
    </tr>
    <tr>
      <td class='line'>131</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l131s0'>                throw new IGraphServerException("Failed to sendRequest with ExecutionException:[" + e.getMessage()</pre></td>
    </tr>
    <tr>
      <td class='line'>132</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        + "] and requestContext:[" + requestContext + "]", e);</pre></td>
    </tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>134</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l134s0'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>136</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l136s0' title='Executions: 1' class='covered'>if (byteArray == null</span> || <span id='l136s1' title='Executions: 1' class='covered'>byteArray.length == 0)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>137</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>            <span id='l137s0' title='Executions: 0' class='uncovered'>throw new IGraphServerException("Failed to sendRequest with " + (byteArray == null</span> ? <span id='l137s1' title='Executions: 0' class='uncovered'>"null"</span> : <span id='l137s2' title='Executions: 0' class='uncovered'>"empty")</span></pre></td>
    </tr>
    <tr>
      <td class='line'>138</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + " response, statusCode:[" + statusCode + "] and requestContext:[" + requestContext + "]");</pre></td>
    </tr>
    <tr>
      <td class='line'>139</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>140</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l140s0'>        requestContext.setResponseContentLength(byteArray.length);</pre></td>
    </tr>
    <tr>
      <td class='line'>141</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l141s0'>        return byteArray;</pre></td>
    </tr>
    <tr>
      <td class='line'>142</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>144</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    protected void appendHeaders(RequestContext requestContext,  AsyncHttpClient.BoundRequestBuilder request) {</pre></td>
    </tr>
    <tr>
      <td class='line'>145</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l145s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>147</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private List&lt;SingleQueryResult> parseResult(PGResult pgResult, RequestContext requestContext) {</pre></td>
    </tr>
    <tr>
      <td class='line'>148</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l148s0'>        List&lt;Result> resultList = pgResult.getResultList();</pre></td>
    </tr>
    <tr>
      <td class='line'>149</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l149s0'>        List&lt;SingleQueryResult> singleResultList = new ArrayList&lt;SingleQueryResult>(pgResult.getResultCount());</pre></td>
    </tr>
    <tr>
      <td class='line'>150</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l150s0' title='Executions: 1' class='covered'>for (Result result</span> : <span id='l150s1' title='Executions: 1' class='covered'>resultList)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>151</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l151s0'>            SingleQueryResult singleQueryResult = new SingleQueryResult();</pre></td>
    </tr>
    <tr>
      <td class='line'>152</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l152s0'>            singleResultList.add(singleQueryResult);</pre></td>
    </tr>
    <tr>
      <td class='line'>153</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l153s0'>            List&lt;ErrorResult> errorList = result.getErrorList();</pre></td>
    </tr>
    <tr>
      <td class='line'>154</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l154s0'>            boolean hasError = false;</pre></td>
    </tr>
    <tr>
      <td class='line'>155</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>            <span id='l155s0' title='Executions: 1' class='covered'>if (!errorList.isEmpty())</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>156</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l156s0'>                StringBuilder errorString = new StringBuilder();</pre></td>
    </tr>
    <tr>
      <td class='line'>157</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l157s0'>                hasError = true;</pre></td>
    </tr>
    <tr>
      <td class='line'>158</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l158s0'>                singleQueryResult.setHasError(hasError);</pre></td>
    </tr>
    <tr>
      <td class='line'>159</td><td class='count'>0</td>
      <td><pre class='prettyprint jmp'>                <span id='l159s0' title='Executions: 0' class='uncovered'>for (ErrorResult errorResult</span> : <span id='l159s1' title='Executions: 0' class='uncovered'>errorList)</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>160</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l160s0'>                    String errorMessage = errorResult.getErrorMessage();</pre></td>
    </tr>
    <tr>
      <td class='line'>161</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l161s0'>                    int errorCode = errorResult.getErrorCode();</pre></td>
    </tr>
    <tr>
      <td class='line'>162</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l162s0'>                    errorString.append(errorCode).append(":").append(errorMessage);</pre></td>
    </tr>
    <tr>
      <td class='line'>163</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l163s0'>                }</pre></td>
    </tr>
    <tr>
      <td class='line'>164</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l164s0'>                singleQueryResult.setErrorMsg(errorString.toString());</pre></td>
    </tr>
    <tr>
      <td class='line'>165</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>166</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l166s0'>            MatchRecords records = result.getRecords();</pre></td>
    </tr>
    <tr>
      <td class='line'>167</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l167s0'>            int recordArrayCount = records.getRecordArrayCount();</pre></td>
    </tr>
    <tr>
      <td class='line'>168</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>            <span id='l168s0' title='Executions: 1' class='covered'>if (hasError</span> && <span id='l168s1' title='Executions: 0' class='uncovered'>recordArrayCount &lt; 1)</span> { // 如果有error，而且结果返回为空，则抛异常</pre></td>
    </tr>
    <tr>
      <td class='line'>169</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l169s0'>                throw new IGraphQueryException(IGraphQueryException.buildErrorMessage(requestContext,</pre></td>
    </tr>
    <tr>
      <td class='line'>170</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                        singleQueryResult.getErrorMsg()));</pre></td>
    </tr>
    <tr>
      <td class='line'>171</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>172</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l172s0'>            singleQueryResult.setResult(records);</pre></td>
    </tr>
    <tr>
      <td class='line'>173</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l173s0'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>174</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l174s0'>        return singleResultList;</pre></td>
    </tr>
    <tr>
      <td class='line'>175</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>177</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private void checkStatus(Status status, RequestContext requestContext) {</pre></td>
    </tr>
    <tr>
      <td class='line'>178</td><td class='count'>1</td>
      <td><pre class='prettyprint jmp'>        <span id='l178s0' title='Executions: 1' class='covered'>if (!status.equals(Status.FINISHED))</span> {</pre></td>
    </tr>
    <tr>
      <td class='line'>179</td><td class='count'>0</td>
      <td><pre class='prettyprint uncovered' id='l179s0'>            throw new IGraphQueryException(IGraphQueryException.buildErrorMessage(requestContext, status.toString()));</pre></td>
    </tr>
    <tr>
      <td class='line'>180</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>181</td><td class='count'>1</td>
      <td><pre class='prettyprint covered' id='l181s0'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>183</td><td class='count'>2</td>
      <td><pre class='prettyprint covered' id='l183s0'>    enum RequestType {</pre></td>
    </tr>
    <tr>
      <td class='line'>184</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        POST, GET</pre></td>
    </tr>
    <tr>
      <td class='line'>185</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr>
      <td class='line'>186</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
